<%@page import="com.xnx3.j2ee.Global"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>  
<%@ taglib uri="http://www.xnx3.com/java_xnx3/xnx3_tld" prefix="x" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<jsp:include page="../../../../iw/common/head.jsp">
	<jsp:param name="title" value="文件列表"/>
</jsp:include>
<script src="<%=basePath+Global.CACHE_FILE %>Branch_branchid.js"></script>

<jsp:include page="../../../../iw/common/list/formSearch_formStart.jsp" ></jsp:include>
	<jsp:include page="../../../../iw/common/list/formSearch_input.jsp">
		<jsp:param name="iw_label" value="文件名"/>
		<jsp:param name="iw_name" value="name"/>
	</jsp:include>
	<jsp:include page="../../../../iw/common/list/formSearch_input.jsp">
		<jsp:param name="iw_label" value="后缀"/>
		<jsp:param name="iw_name" value="suffix"/>
	</jsp:include>
	<jsp:include page="../../../../iw/common/list/formSearch_input.jsp">
		<jsp:param name="iw_label" value="部门"/>
		<jsp:param name="iw_name" value="branchid"/>
		<jsp:param name="iw_type" value="select"/>
	</jsp:include>
	
    <input class="layui-btn iw_list_search_submit" type="submit" value="搜索" />
    
    <div style="float: right; " class="layui-form">
		<script type="text/javascript"> orderBy('addtime_DESC=文件上传时间倒序,size_DESC=文件有大到小,size_ASC=文件有小到大'); </script>
	</div>
</form>

<script>
//输入branchid，输出部门名字
function writeBranchName(branch_id){
	var branchName = branchid[branch_id];
	if(typeof(branchName) == 'undefined' || branchName == 'undefined' || branchName.length == 0 || branchName == '0'){
		branchName = '公共';
	}
	document.write(branchName);
}
</script>

<table class="layui-table iw_table">
  <thead>
    <tr>
		<th>ID</th>
        <th>文件名</th>
        <th>后缀</th>
        <th>大小</th>
        <th>所属用户</th>
        <th>所属部门</th>
        <th>添加时间</th>
        <th>操作</th>
    </tr> 
  </thead>
  <tbody>
  	<c:forEach items="${list}" var="item">
  		<tr>
          <td style="width:28px;">${item.id }</td>
          <td>${item.name }</td>
          <td style="width:50px;">${item.suffix }</td>
          <td style="width:80px;">
          		<x:fileSizeToInfo size="${item.size }000"></x:fileSizeToInfo>
          </td>
          <td style="width:100px; cursor: pointer;" onclick="userView(${item.userid});">${item.nickname }</td>
          <td style="width:120px;"><script>writeBranchName('${item.branchid }');</script></td>
          <td style="width:100px;"><x:time linuxTime="${item.addtime }" format="yy-MM-dd hh:mm"></x:time></td>
          <td style="width: 160px;">
          		<botton class="layui-btn layui-btn-sm" onclick="updateFile('${item.id}');" style="margin-left: 3px;">修改</botton>
          		<botton class="layui-btn layui-btn-sm" onclick="deleteFile('${item.id}','${item.name }');" style="margin-left: 3px;">删除</botton>
          		<a class="layui-btn layui-btn-sm" style="margin-left: 3px;" href="${item.url }" target="_black">下载</a>
          </td>
      </tr>
    </c:forEach>
  </tbody>
</table>
<!-- 通用分页跳转 -->
<jsp:include page="../../../../iw/common/page.jsp"></jsp:include>

<div style="padding:15px;">
	<button class="layui-btn" onclick="updateFile(0);" style="margin-left: 10px;margin-bottom: 20px;"><i class="layui-icon" style="padding-right:8px; font-size: 22px;">&#xe608;</i>添加文件</button>
</div>

<script type="text/javascript">

//查看用户详情信息
function userView(id){
	layer.open({
		type: 2, 
		title:'查看用户信息', 
		area: ['460px', '630px'],
		shadeClose: true, //开启遮罩关闭
		content: '<%=basePath %>admin/user/view.do?id='+id
	});
}

//修改、添加文件
function updateFile(id){
	layer.open({
		type: 2, 
		title: id > 0 ? '修改文件':'添加文件', 
		area: ['460px', '260px'],
		shadeClose: true, //开启遮罩关闭
		content: 'file.do?id='+id
	});
}


/**
 * 删除，传入要删除的文件信息的id
 */
function deleteFile(id, name){
	var dtv_confirm = layer.confirm('删除后不可恢复，您确定要删除文件 【 '+name+' 】 吗？', {
	  btn: ['删除','取消'] //按钮
	}, function(){
		layer.close(dtv_confirm);
		parent.iw.loading("删除中");
		$.post("deleteFile.do?id="+id, function(data){
			parent.iw.loadClose();
			if(data.result == '1'){
				parent.iw.msgSuccess("删除成功");
				location.reload();
	     	}else if(data.result == '0'){
	     		parent.iw.msgFailure(data.info);
	     	}else{
	     		parent.iw.msgFailure();
	     	}
		});
    }, function(){
	});
}
</script>

<jsp:include page="../../../../iw/common/foot.jsp"></jsp:include>